<template>
  <div class="advanced-setting">
    <el-form ref="formRef" size="large" label-width="100px" label-position="left">
      <el-form-item>
        <template #label>
          <div class="label">
            提交人权限
          </div>
        </template>
        <div class="item-row">
          <el-checkbox v-model="formData.flowAllowRevoke">
            <div>允许撤销审批中的申请</div>
          </el-checkbox>
          <span>第一个审批节点通过后，提交人扔可撤销申请（配置前已发起的申请不生效）</span>
        </div>
        <div class="item-row">
          <el-checkbox v-model="formData.flowAgencySubmit">
            <div>允许代他人提交</div>
          </el-checkbox>
          <span>代提人和实际提交人都需在该审批的发起范围内，提交后将共享审批单后续状态</span>
        </div>
      </el-form-item>

      <el-form-item>
        <template #label>
          <div class="label">
            审批人去重
          </div>
        </template>
        <div class="item-row">
          <div>同一审批人在流程中重复出现时：</div>
          <el-radio-group v-model="formData.flowApproval" class="ml-4">
            <el-radio :label="0" size="large">仅审批一次，后续重复的审批节点均自动同意</el-radio>
            <el-radio :label="1" size="large">不自动同意，每个节点都需要审批</el-radio>
          </el-radio-group>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { reactive, watch } from 'vue'

export default {
  props: {
    modelValue: {
      type: Object,
      default: () => {}
    }
  },
  emits: ['update:modelValue'],
  setup(props, { emit }) {
    const formData = reactive({
      flowAllowRevoke: false, // 允许撤销审批中的申请
      flowAgencySubmit: false, // 允许代他人提交
      flowApproval: 0 // 审批人去重 0仅审批一次 1每个节点都要审批
    })
    Object.assign(formData, props.modelValue)

    watch(formData, () => {
      emit('update:modelValue', formData)
    }, { immediate: true })

    return {
      formData
    }
  }
}
</script>

<style lang="scss" scoped>
.label {
  font-size: 16px;
  font-weight: 600;
}
.item-row {
  width: 100%;
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;

  span {
    font-size: 12px;
    color: #909399;
    line-height: 16px;
    padding-left: 22px;
  }
}
</style>
